function update1(productId) {
    document.getElementById("div1").style.display='none'
    document.getElementById("div2").style.display='block'
    var myDate = new Date();
    year = myDate.getYear()+1900;
    month = myDate.getMonth()+1;
    date = myDate.getDate();
    hour = myDate.getHours();
    minute =myDate.getMinutes();
    second = myDate.getSeconds();
    $.ajax({
        type:"get",
        url: "/cha/xx/"+productId,
        dataType:"json",
        success:function (data) {
            document.getElementById("cpmc").innerText=data.productName
            document.getElementById("cpbh").innerText=data.productId
            document.getElementById("djr").value=data.register
            document.getElementById("shijian").innerText=year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
        },error:function (data) {
            console.log("Xxx")
        }
    })
}
function fanhui() {
    document.location="designn.jsp"
}
//添加工序
function cstj() {
    let cs1 = document.getElementById("cs1").innerText;
    let cs2 = document.getElementById("cs2").innerText;
    let cs3 = document.getElementById("cs3").innerText;
    if (document.getElementById("cs22")==null) {
        document.getElementById("tableOnlineEdit").innerHTML +=
            "<tr>" +
            "<td><input  type='checkbox' name='car'></td>" +
            "<td><span id='cs22'>" + cs2 + "</span></td>" +
            "<td><span name='pd'>"+cs1+"</span></td>" +
            "<td><span id='cs3'>" + cs3 + "</span></td>" +
            "<td><input type='text' id='cs4' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><input type='text' id='cs5' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><input type='text' id='cs6' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><span id='csjg'></span></td>" +
            "</tr>"
    }else {
        return false;
    }
}
function bztj() {
    let bz1 = document.getElementById("bz1").innerText;
    let bz2 = document.getElementById("bz2").innerText;
    let bz3 = document.getElementById("bz3").innerText;
    if (document.getElementById("bz22")==null) {
        document.getElementById("tableOnlineEdit").innerHTML +=
            "<tr>" +
            "<td><input type='checkbox' name='car'></td>" +
            "<td><span id='bz22'>" + bz2 + "</span></td>" +
            "<td><span name='pd'>"+bz1+"</span></td>" +
            "<td><span id='bz3'>" + bz3 + "</span></td>" +
            "<td><input type='text' id='bz4' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><input type='text' id='bz5' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><input type='text' id='bz6' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><span id='bzjg'></span></td>" +
            "</tr>"
    }else {
        return false;
    }
}

function zztj() {
    let zz1 = document.getElementById("zz1").innerText;
    let zz2 = document.getElementById("zz2").innerText;
    let zz3 = document.getElementById("zz3").innerText;
    if (document.getElementById("zz22")==null) {
        document.getElementById("tableOnlineEdit").innerHTML +=
            "<tr>" +
            "<td><input type='checkbox' name='car'></td>" +
            "<td><span id='zz22'>" + zz2 + "</span></td>" +
            "<td><span name='pd'>"+zz1+"</span></td>" +
            "<td><span id='zz3'>" + zz3 + "</span></td>" +
            "<td><input type='text' id='zz4' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><input type='text' id='zz5' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><input type='text' id='zz6' style='background: lightgoldenrodyellow;border: 1px'></td>" +
            "<td><span id='zzjg'></span></td>" +
            "</tr>"
    }else {
        return false;
    }
}
//删除工序
function delSelect() {
    let car = document.getElementsByName("car");
    for(let i=car.length-1;i>=0;i--){
        if (car[i].checked==true){
            car[i].parentNode.parentNode.parentNode.remove();
        }
    }
}
function check() {

    let val = document.getElementById("tableOnlineEdit").querySelectorAll("tbody");
    if(val.length>0){
        return true;
    }
        return false;
}
//计算工序成本结果
function yuelan() {
    if (!check()) {
        alert("请添加工序")
        return false;
    } else {
        let cs = document.getElementById("cs22").innerText;
        let zz = document.getElementById("zz22").innerText;
        if (cs=="测试") {
            let cs4 = document.getElementById("cs4").value;
            let cs5 = document.getElementById("cs5").value;
            let cs6 = document.getElementById("cs6").value;
            var csjg1 = cs6 * cs4;
            document.getElementById("csjg").innerText = csjg1
            if (zz=="组装") {
                let zz4 = document.getElementById("zz4").value;
                let zz5 = document.getElementById("zz5").value;
                let zz6 = document.getElementById("zz6").value;
                var zzjg1 = zz6 * zz4;
                document.getElementById("zzjg").innerText = zzjg1
                let bz = document.getElementById("bz22").innerText;
                if (bz!=null) {
                    console.log(bz)
                    let bz4 = document.getElementById("bz4").value;
                    let bz5 = document.getElementById("bz5").value;
                    let bz6 = document.getElementById("bz6").value;
                    var bzjg1 = bz4 * bz6;
                    document.getElementById("bzjg").innerText = bzjg1
                }else {
                    console.log("为空")
                }
            }else {
                console.log("为空")
            }
        }else {
            console.log("为空")
        }

        let productId = document.getElementById("cpbh").innerText;
        let gsjg = csjg1+zzjg1+bzjg1;

        var xx={
            productName:document.getElementById("cpmc").innerText,
            productId:document.getElementById("cpbh").innerText,
            procedureDescribe:document.getElementById("sjyq").value,
            costPriceSum:gsjg,
            designer:document.getElementById("sjr").value,
            register:document.getElementById("djr").value,
            registerTime:document.getElementById("shijian").innerText,
        }
        let mDesignProcedure = JSON.stringify(xx);
        $.ajax({
            type:"post",
            dataType:"json",
            data:mDesignProcedure,
            contentType: "application/json",
            url:"/cha/add/",
            success:function (data) {
                $("#table").bootstrapTable("refresh")

            },error:function (data) {
                console.log("Xxxxx")
            }
        })
        $.ajax({
            type: "post",
            url: "/cha/up/" +productId,
            dataType: "json",
            success:function (data) {

            }
        })

        if (document.getElementById("zz22").innerText!=null) {
            var xx1 = {
                parentId:document.getElementById("cpbh").innerText,
                procedureId: document.getElementById("zz1").innerText,
                procedureName: document.getElementById("zz2").innerText,
                labourHourAmount: document.getElementById("zz4").value,
                amountUnit: document.getElementById("zz5").value,
                costPrice: document.getElementById("zz6").value,
                subtotal: document.getElementById("zzjg").innerText,
                register: document.getElementById("djr").value,
                registerTime: document.getElementById("shijian").innerText
            }
            let mDesignProcedureDetails = JSON.stringify(xx1);
            $.ajax({
                type: "post",
                dataType: "json",
                data: mDesignProcedureDetails,
                contentType: "application/json",
                url: "/cha/add1/",
                success: function (data) {

                }
            })
        }
        if (document.getElementById("bz22").innerText!=null) {
            var xx1 = {
                parentId:document.getElementById("cpbh").innerText,
                procedureId: document.getElementById("bz1").innerText,
                procedureName: document.getElementById("bz2").innerText,
                labourHourAmount: document.getElementById("bz4").value,
                amountUnit: document.getElementById("bz5").value,
                costPrice: document.getElementById("bz6").value,
                subtotal: document.getElementById("bzjg").innerText,
                register: document.getElementById("djr").value,
                registerTime: document.getElementById("shijian").innerText
            }
            let mDesignProcedureDetails = JSON.stringify(xx1);
        $.ajax({
            type:"post",
            dataType:"json",
            data:mDesignProcedureDetails,
            contentType:"application/json",
            url:"/cha/add1",
            success:function (data) {

            }
        });
        }
        let innerText = document.getElementById("cpbh").innerText;
        console.log(innerText)
        if (document.getElementById("cs22").innerText!=null) {
            var xx1 = {
                parentId:document.getElementById("cpbh").innerText,
                procedureId: document.getElementById("cs1").innerText,
                procedureName: document.getElementById("cs2").innerText,
                labourHourAmount: document.getElementById("cs4").value,
                amountUnit: document.getElementById("cs5").value,
                costPrice: document.getElementById("cs6").value,
                subtotal: document.getElementById("csjg").innerText,
                register: document.getElementById("djr").value,
                registerTime: document.getElementById("shijian").innerText
            }
            let mDesignProcedureDetails = JSON.stringify(xx1);
            $.ajax({
                type: "post",
                dataType: "json",
                data: mDesignProcedureDetails,
                contentType: "application/json",
                url: "/cha/add1/",
                success: function (data) {
                    $("#table").bootstrapTable("refresh");
                    document.getElementById("div2").style.display='none'
                    document.getElementById("div1").style.display='block'
                }
            })
        }
    }
}
$(function () {
    $("#table").bootstrapTable({
        method:"post",
        //请求类型
        contentType:"application/json",
        //请求地址
        url:"/cha",
        striped:true,
        //初始页数
        pageNumber:1,
        pagination: true,
        sidePagination:"server",
        pageSize:2,
        pageList:[2,4,6,8,10],
        queryParams:function (param) {
            return {
                page: (param.offset / param.limit) + 1,
                pageNum: param.limit,
                firstKindName:document.getElementById("firstKindName").value,
                secondKindName:document.getElementById("secondKindName").value,
                thirdKindName:document.getElementById("thirdKindName").value,
                register_time1:document.getElementById("register_time1").value,
                register_time2:document.getElementById("register_time2").value
            }
        },
        columns:[
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名称",field:"productName",align:"center"},
            {title:"档次级别",field:"productClass",align:"center"},
            {title:"I级分类",field:"firstKindName",align:"center"},
            {title:"II级分类",field:"secondKindName",align:"center"},
            {title:"III级分类",field:"thirdKindName",align:"center"},
            {title:"产品经理",field:"responsiblePerson",align:"center"},
            {title:"制定设置单",field:"",align:"center",
                formatter:function (value, row, index) {
                    var btn2="<button class='btn btn-info'  onclick='update1("+row.productId+")'>制作设计单</button>";
                    return btn2;
                }}
        ]
    })
    $("#submit_select").click(function () {
        $("#table").bootstrapTable("refresh");
    })
})
